<?php
require_once 'ActionFramework/inputs.php';

class ListInputTestCase extends PHPUnit_Framework_TestCase
{
    public function testVanilla()
    {
    	$input = new ListInput('DUMMY_NAME', 'dummy name', 
    				new EmailInput()
    			 );
    	
    	$result = $input->validate('["you@me.org"]');
    	$this->assertTrue($result['valid']);
    	
    	$result = $input->validate('["no.emailaddress"]');
    	$this->assertFalse($result['valid']);
    	
    	$result = $input->validate('[]');
    	$this->assertTrue($result['valid']);
    	
    }
    
    public function testMinLength()
    {
    	$input = new ListInput('DUMMY_NAME', 'dummy name', 
    				new EmailInput(), 1
    			 );
    	
    	$result = $input->validate('["you@me.org"]');
    	$this->assertTrue($result['valid']);
    	
    	$result = $input->validate('["no.emailaddress"]');
    	$this->assertFalse($result['valid']);
    	
    	$result = $input->validate('[]');
    	$this->assertFalse($result['valid']);
    	
    }
    
    public function testMaxLength()
    {
    	$input = new ListInput('DUMMY_NAME', 'dummy name', 
    				new EmailInput(), null, 3
    			 );
    	
    	$result = $input->validate('["you@me.org"]');
    	$this->assertTrue($result['valid']);
    	
    	$result = $input->validate('["no.emailaddress"]');
    	$this->assertFalse($result['valid']);
    	
    	$result = $input->validate('[]');
    	$this->assertTrue($result['valid']);
    	
    	$result = $input->validate('["you@me.org", "you@me.org", "you@me.org", "you@me.org"]');
    	$this->assertFalse($result['valid']);
    	
    }
    
    public function testCombination()
    {
    	$input = new ListInput('DUMMY_NAME', 'dummy name', 
    				new EmailInput(), 2, 3
    			 );
    	
    	$result = $input->validate('["you@me.org"]');
    	$this->assertFalse($result['valid']);
    	
    	$result = $input->validate('["no.emailaddress"]');
    	$this->assertFalse($result['valid']);
    	
    	$result = $input->validate('["you@me.org", "you@me.org"]');
    	$this->assertTrue($result['valid']);
    	
    	$result = $input->validate('["you@me.org", "you@me.org", "you@me.org", "you@me.org"]');
    	$this->assertFalse($result['valid']);
    	
    }
    
    public function testRubbish()
    {
    	$input = new ListInput('DUMMY_NAME', 'dummy name', 
    				new EmailInput(), 2, 3
    			 );
    	
    	$result = $input->validate('038#(R3ourqJ#3wr');
    	$this->assertFalse($result['valid']);
    	
    }
}